package com.qfjy.config.example5;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class BlogTopicExchangeConfig {
    /**
     * 1、定义交换机
     * 2、分别定义队列
     * 3、交换机和队列进行绑定
     */
    @Bean
    public TopicExchange blogTopicExchange(){

        return new TopicExchange("blogTopicExchange");
    }

    /**
     * #TODO 2、定义队列
     */
    @Bean
    public Queue javaQueue(){
        return new Queue("javaQueue");
    }

    @Bean
    public Queue pythonQueue(){
        return new Queue("pythonQueue");
    }

    @Bean
    public Queue allQueue(){
        return new Queue("allQueue");
    }

    /**
     * #3 交换机依次和队列进行绑定
     */
    @Bean
    public Binding bindJavaQueueTopicExchange(Queue javaQueue,TopicExchange blogTopicExchange){
        return BindingBuilder.bind(javaQueue).to(blogTopicExchange).with("blog.java");
    }

    @Bean
    public Binding bindPythonQueueTopicExchange(Queue pythonQueue,TopicExchange blogTopicExchange){
        return BindingBuilder.bind(pythonQueue).to(blogTopicExchange).with("blog.python");
    }

    @Bean
    public Binding bindAllQueueTopicExchange(Queue allQueue,TopicExchange blogTopicExchange){
        return BindingBuilder.bind(allQueue).to(blogTopicExchange).with("blog.#");
    }
}
